package br.edu.unifei.cct720.alieninvasion.entity.ship;

import br.edu.unifei.cct720.alieninvasion.entity.Entity;
import br.edu.unifei.cct720.alieninvasion.entity.alien.AlienEntity;
import br.edu.unifei.cct720.alieninvasion.entity.alien.AlienMotherShipEntity;
import br.edu.unifei.cct720.alieninvasion.entity.alien.AlienShipEntity;
import br.edu.unifei.cct720.alieninvasion.entity.alien.AlienShotEntity;
import br.edu.unifei.cct720.alieninvasion.main.gui.GameCanvas;

/**
 * Class to represent an entity of the player's ship
 * 
 * @author Felipe Knappe
 */
public class ShipEntity extends Entity {

	/**
	 * Class Constructor
	 * 
	 * Create a new player ship entity
	 * 
	 * @param game The game in which the shot has been created
	 * @param ref The refence to the sprite representative of this entity
	 * @param x The initial x-coordinate of the entity
	 * @param y The initial y-coordinate of the entity
	 */
	public ShipEntity(GameCanvas game, String ref, int x, int y) {
		super(game, ref, x, y);
	}
	
	/**
	 * Method responsible for request that this entity move 
	 * itself based on time elapsed.
	 * 
	 * @param delta The entity shift value
	 * 
	 */
	public void move(long delta) {
		/* 
		 * If the entity reached the left hand side of the screen and
		 * are moving left then don't move to left anymore
		 */
		if ((dx < 0) && (x < 10)) {
			return;
		}
		
		/*
		 * Otherwise, if reached the right hand side of the screen
		 * and are moving to right then don't move to right anymore
		 */
		if ((dx > 0) && (x > 750)) {
			return;
		}
		
		// proceed with normal move 
		super.move(delta);
	}
	
	/**
	 * Method responsible for notify this entity that it has collided with 
	 * another entity.
	 * 
	 * @param other The other entity with which we've collided
	 * 
	 */
	public void collidedWith(Entity other) {
		// if its an alien, notify the game that the player
		// is dead
		if (other instanceof AlienEntity ||
			other instanceof AlienShipEntity ||
			other instanceof AlienMotherShipEntity ||
			other instanceof AlienShotEntity) {
			game.notifyDeath();
		}
	}
}